<?php

namespace App\Admin\Controllers;

use App\Admin\Renderable\JobPositionTab;
use App\Admin\Repositories\JobPositionRecommend;
use App\Models\CompanyModel;
use App\Models\JobpositionModel;
use App\Models\JobPositionRecommendModel;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class JobPositionRecommendController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new JobPositionRecommend(['jobPositionInfo']), function (Grid $grid) {
            $grid->model()->orderBy('sort');
            $grid->column('id');
            $grid->column('job_position_id');
            $grid->column('jobPositionInfo.position_name','职位名称');
            $grid->column('jobPositionInfo.company', '公司')->display(function ($value) {
                return $value->cur_type == CompanyModel::TYPE_PERSON ? $value->contact_person_name : $value->company_name;
            });
            $grid->column('sort','排序')->editable(true);

            $grid->column('jobPositionInfo.salary','薪资');
            $grid->column('jobPositionInfo.expected_num','招聘人数');
            $grid->column('jobPositionInfo.recruit_num','实际招聘人数');
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            //边框模式
            $grid->withBorder();
            //横向滚动条
            $grid->scrollbarX();
            // 禁用批量删除按钮
//            $grid->disableBatchDelete();
            // 禁用显示按钮
            $grid->disableViewButton();
//            $grid->disableRowSelector();
//            $grid->disableDeleteButton();
            $grid->disableEditButton();
            $grid->option('dialog_form_area', ['700px', '350px'])->enableDialogCreate(); //
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new JobPositionRecommend(), function (Form $form) {
            $form->display('id');
            $notIds = JobPositionRecommendModel::query()->pluck('job_position_id')->toArray();
            $form->multipleSelectTable('job_position_id','选择岗位')
                ->title('岗位选择')
                ->from(JobPositionTab::make()->payload(['notIds'=>$notIds]))
                ->model(JobpositionModel::class, 'id', 'position_name');
            $form->hidden('sort')->default(0);
            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
